package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shenguohui
 * @since 2024-08-19
 */
@RestController
@Api(value="用户管理Controller")
public class UserController {
    private static final String RELATIVE_PATH="/api";
    private static final String INSTRUMENT_PATH="/user";
    @Autowired
    private IUserService iUserService;
    @ApiOperation(value="查询用户信息",notes="查询用户信息")
    @ApiParam(value="通过用户id查询用户信息",required=true)
    @RequestMapping(value=RELATIVE_PATH+INSTRUMENT_PATH+"/getUserById",method= RequestMethod.POST)
    public ResponseEntity getUserById(@RequestBody String id){
//        List<User> userList = iUserService.lambdaQuery().eq(User::getId,id).list();
        User user = iUserService.lambdaQuery().eq(User::getId, Long.parseLong(id)).oneOpt().orElse(null);
        return user != null ? ResponseEntity.ok(user) : ResponseEntity.ok("无此数据") ;
    }
    @RequestMapping(value=RELATIVE_PATH+INSTRUMENT_PATH+"/hello",method= RequestMethod.POST)
    public String hello(@RequestBody String id) {
        return "hello";
    }
}
